<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/WEB-TAG/platForm.tld" prefix="PF"%>
<table id="dataTitleGrid">
	<thead>
		<tr>
			<th data-options="field:'ck',checkbox:true"></th>
			<th field="TITLE" data-options="sortable:true" width="40">
				标题文本
			</th>
			<th field="FIELDNAME" data-options="sortable:true" width="40">
				字段名称
			</th>
			<th field="SORT" data-options="sortable:true" width="40">
				显示排序
			</th>
			<th field="FIXIS" data-options="sortable:true" width="40">
				是否冻结
			</th>
			<th field="WIDTH" data-options="sortable:true" width="20">
				宽度
			</th>
			<th field="DICTYPE" data-options="sortable:true" width="40">
				转义类型
			</th>
		</tr>
	</thead>
</table>
<script type="text/javascript">
	var url_delActionTitle = "admin/FarmFormsTitledeleteCommit.do";//删除URL
	var url_formActionTitle = "admin/FarmFormsTitleShow.do";//增加、修改、查看URL
	var url_searchActionTitle = "admin/FarmFormsTitleQuery.do";//查询URL
	var title_windowTitle = "结果集合管理";//功能名称
	var gridTitle;//数据表格对象
	var toolBarTitle = [ {
		id : 'view',
		text : '查看',
		iconCls : 'icon-tip',
		handler : viewDataTitle
	}, {
		id : 'init',
		text : '自动生成',
		iconCls : 'icon-add',
		handler : initTitles
	}, {
		id : 'add',
		text : '新增',
		iconCls : 'icon-add',
		handler : addDataTitle
	}, {
		id : 'edit',
		text : '修改',
		iconCls : 'icon-edit',
		handler : editDataTitle
	}, {
		id : 'del',
		text : '删除',
		iconCls : 'icon-remove',
		handler : delDataTitle
	} ];
	$(function() {
		//初始化数据表格
		gridTitle = $('#dataTitleGrid').datagrid( {
			url : url_searchActionTitle,
			fit : true,
			fitColumns : true,
			'toolbar' : toolBarTitle,
			pagination : true,
			closable : true,
			checkOnSelect : true,
			striped : true,
			rownumbers : true,
			ctrlSelect : true,
			queryParams : {
				ids : $('#domTabsId').val()
			}
		});
	});
	//查看
	function viewDataTitle() {
		var selectedArray = $(gridTitle).datagrid('getSelections');
		if (selectedArray.length == 1) {
			var url = url_formActionTitle + '?pageset.pageType='
					+ PAGETYPE.VIEW + '&ids=' + selectedArray[0].ID;
			$.farm.openWindow( {
				id : 'winTitle',
				width : 600,
				height : 300,
				modal : true,
				url : url,
				title : '浏览'
			});
		} else {
			$.messager.alert(MESSAGE_PLAT.PROMPT, MESSAGE_PLAT.CHOOSE_ONE_ONLY,
					'info');
		}
	}
	//新增
	function addDataTitle() {
		var url = url_formActionTitle + '?ids=' + $('#domTabsId').val()
				+ '&pageset.pageType=' + PAGETYPE.ADD;
		$.farm.openWindow( {
			id : 'winTitle',
			width : 600,
			height : 300,
			modal : true,
			url : url,
			title : '新增'
		});
	}
	//修改
	function editDataTitle() {
		var selectedArray = $(gridTitle).datagrid('getSelections');
		if (selectedArray.length == 1) {
			var url = url_formActionTitle + '?pageset.pageType='
					+ PAGETYPE.EDIT + '&ids=' + selectedArray[0].ID;
			$.farm.openWindow( {
				id : 'winTitle',
				width : 600,
				height : 300,
				modal : true,
				url : url,
				title : '修改'
			});
		} else {
			$.messager.alert(MESSAGE_PLAT.PROMPT, MESSAGE_PLAT.CHOOSE_ONE_ONLY,
					'info');
		}
	}
	//初始化结果集合字段
	function initTitles() {
		// 有数据执行操作
		var str = "是否初始化结果集合，该操作将删除现有集合且无法恢复?";
		$.messager.confirm(MESSAGE_PLAT.PROMPT, str, function(flag) {
			if (flag) {
				$(gridTitle).datagrid('loading');
				$.post("admin/FarmFormsInitTitleCommit.do" + '?ids='
						+ $('#domTabsId').val(), {}, function(flag) {
					$(gridTitle).datagrid('loaded');
					if (flag.pageset.commitType == 0) {
						$(gridTitle).datagrid('reload');
					} else {
						var str = MESSAGE_PLAT.ERROR_SUBMIT
								+ flag.pageset.message;
						$.messager.alert(MESSAGE_PLAT.ERROR, str, 'error');
					}
				});
			}
		});
	}
	//删除
	function delDataTitle() {
		var selectedArray = $(gridTitle).datagrid('getSelections');
		if (selectedArray.length > 0) {
			// 有数据执行操作
			var str = selectedArray.length + MESSAGE_PLAT.SUCCESS_DEL_NEXT_IS;
			$.messager.confirm(MESSAGE_PLAT.PROMPT, str, function(flag) {
				if (flag) {
					$(gridTitle).datagrid('loading');
					$.post(url_delActionTitle + '?ids='
							+ $.farm.getCheckedIds(gridTitle, 'ID'), {},
							function(flag) {
								$(gridTitle).datagrid('loaded');
								if (flag.pageset.commitType == 0) {
									$(gridTitle).datagrid('reload');
								} else {
									var str = MESSAGE_PLAT.ERROR_SUBMIT
											+ flag.pageset.message;
									$.messager.alert(MESSAGE_PLAT.ERROR, str,
											'error');
								}
							});
				}
			});
		} else {
			$.messager.alert(MESSAGE_PLAT.PROMPT, MESSAGE_PLAT.CHOOSE_ONE,
					'info');
		}
	}
</script>